package net.thxjj.adminServer.util;

import java.text.DecimalFormat;

public class DataUtils {
    /*
     * 如果是小数，保留两位，非小数，保留整数
     * @param number
     */
    public static String getDoubleString(double number) {
        String numberStr;
        if (((int) number * 1000) == (int) (number * 1000)) {
            //如果是一个整数
            numberStr = String.valueOf((int) number);
        } else {
            DecimalFormat df = new DecimalFormat("######0.00");
            numberStr = df.format(number);
        }
        return numberStr;
    }

    public static String getDoubleString(String number) {

        if(Tools.isEmpty(number)){
            return "";
        }

        try {
            double numbuf = Double.parseDouble(number);
            //如果是一个整数
            DecimalFormat df = new DecimalFormat("######0.00");
            return df.format(numbuf);
        }catch (NumberFormatException e){
            return "";
        }
    }

}
